<?php

namespace App\Models;

use Illuminate\Support\Facades\Db;

class Permission
{

    public static function check($user,$route){

        $nodes = Db::table('role')->where('id',$user->role_id)->value('nodes');
        $allows = explode(',',$nodes);

        $id = Db::table('node')->where('route',$route)->first();
        if(!$id){
            return true;
        }
        if(in_array($id->id,$allows)){
            return true;
        }
        return false;

    }

}
